package cn.ultrarisk.scadmin.manager.biz.context;

import cn.ultrarisk.scadmin.manager.biz.user.entity.Admin;
import cn.ultrarisk.scadmin.manager.biz.user.util.SessionUtil;
import cn.ultrarisk.scadmin.manager.util.WebUtil;

import javax.servlet.http.HttpServletRequest;

/**
 * RequestContext
 *
 * @author sevendlong(lin23871@163.com)
 * @date 2013-11-8
 * @since V1.0
 */
public class RequestContext {
    private static ThreadLocal<HttpServletRequest> requestThreadLocal = new ThreadLocal<HttpServletRequest>();

    public static String getIp() {
        HttpServletRequest request = getRequest();
        return request != null ? WebUtil.getRemoteIP(request) : null;
    }

    public static Admin getAdmin() {
        HttpServletRequest request = getRequest();
        return request != null ? SessionUtil.getAdmin() : null;
    }

    public static HttpServletRequest getRequest() {
        return requestThreadLocal.get();
    }

    public static void setRequest(HttpServletRequest request) {
        requestThreadLocal.set(request);
    }

    public static void removeRequest() {
        requestThreadLocal.remove();
    }
}
